<template>
	<view>
		<lq-title title="修改密码"></lq-title>
		<view class="parent">
			<view class="input-container">
				<view class="label"> 原密码 </view>
				<input class="et" placeholder="请输入原密码" v-model="form.password" password placeholder-class="holder"/>
			</view>

			<view class="input-container">
				<view class="label"> 新密码 </view>
				<input class="et" placeholder="请输入新密码" v-model="form.newpassword" password placeholder-class="holder"/>
			</view>

			<view class="input-container">
				<view class="label"> 再次密码 </view>
				<input class="et" placeholder="请输入再次密码" v-model="form.surepassword" password placeholder-class="holder"/>
			</view>

			<lq-button text="保存" @click.native="onRegister" style="margin-top: 100rpx"></lq-button>
		</view>
	</view>
</template>

<script>
	import md5 from '@/common/md5.js';
	export default {
		data() {
			return {
				form: {
					password: '',
					newpassword: '',
					surepassword: '',
				}
			}
		},
		methods: {
			async onRegister() {
				if (!this.form.password) {
					this.$common.showToast('请输入原密码')
					return
				}
				if (!this.form.newpassword) {
					this.$common.showToast('请输入新密码')
					return
				}
				if (this.form.newpassword != this.form.surepassword) {
					this.$common.showToast('两次密码不一致')
					return
				}
				let params = {
					password: md5.hex_md5(this.form.password),
					newpassword: md5.hex_md5(this.form.newpassword),
					surepassword: md5.hex_md5(this.form.surepassword),
				}

				let res = await this.$common.post('/app/user/xiugai', params);
				if (0 == res.code) {
					this.$common.showToast('修改成功')
					setTimeout(() => {
						uni.navigateBack();
					}, 500);
				} else {
					this.$common.showToast(res.msg)
				}
			},

		}
	}
</script>

<style lang="scss">
	.parent {
		padding: 0 50rpx;
	}

	.input-container {
		display: flex;
		flex-direction: row;
		align-items: center;
		height: 90rpx;
		margin-top: 30rpx;
		background-color: rgba(#000, 0.5);
		border-radius: 10rpx;

		.label {
			width: 150rpx;
			height: 100%;
			line-height: 90rpx;
			font-size: 32rpx;
			color: #888;
			text-align: center;
		}

		.et {
			height: 100%;
			line-height: 100rpx;
			padding: 0 20rpx;
			font-size: 28rpx;
			flex: 1;
			color: #fff;
		}
		
		.holder{
			color: #555;
		}
	}
</style>